# Author:Yiye
# -*- codeing = utf-8 -*-
# @Time :2021/11/11 14:30
# @Author:李卓
# @Site : 
# @File : 第二种反爬.py
# @Software : PyCharm
import gzip
import urllib.request
import urllib.parse
url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
headers = {
    # 'Accept':' */*',
    # #'Accept-Encoding':' gzip, deflate, br',
    # 'Accept-Language':' zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
    # 'Connection':' keep-alive',
    # 'Content-Length':' 136',
    # 'Content-Type':' application/x-www-form-urlencoded; charset=UTF-8',
    # 'Cookie':'BIDUPSID=247EE2B2F15D8CE535A8B90CEF0A31D9; PSTM=1587729559; BAIDUID_BFESS=2CFF6D5EAB76169F6737F1F1C6D50F5F:FG=1; OUTFOX_SEARCH_USER_ID_NCOO=1535700231.3638928; __yjs_duid=1_0787ac2e1647b95e47ada48832f39bbf1618958792857; BDUSS=UU2R2FMN2J0cEozS0k5MlJ5Q2JBejZBQVdrd0hnflNaZ25ldldUTnNJVmV2UEpnRVFBQUFBJCQAAAAAAAAAAAEAAACv2Z6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAF4vy2BeL8tgS; BDUSS_BFESS=UU2R2FMN2J0cEozS0k5MlJ5Q2JBejZBQVdrd0hnflNaZ25ldldUTnNJVmV2UEpnRVFBQUFBJCQAAAAAAAAAAAEAAACv2Z6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAF4vy2BeL8tgS; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1636612356; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; __yjs_st=2_NWMwODRlNTJkNjk0YTM5NGVjNjMwZDZkYWE5NT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NTExNTE1YjBkMjllYjBjYWYzOTJlZDlmMzcwMDljZTM4ZDQ4; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1636617770',
    # 'Host':' fanyi.baidu.com',
    # 'Origin': 'https://fanyi.baidu.com',
    # 'Referer': 'https//fanyi.baidu.com/translate?aldtype=16047&query=love%0D%0A&keyfrom=baidu&smartresult=dict&lang=auto2zh',
    # 'sec-ch-ua':' "Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
    # 'sec-ch-ua-mobile':' ?0',
    # 'sec-ch-ua-platform':' "Windows"',
    # 'Sec-Fetch-Dest':' empty',
    # 'Sec-Fetch-Mode':' cors',
    # 'Sec-Fetch-Site':' same-origin',
    # 'User-Agent':' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36',
    # 'X-Requested-With':' XMLHttpRequest',


}
data = {
    'from':' en',
'to':' zh',
'query':' love',
'simple_means_flag':' 3',
'sign':' 198772.518981',
'token':' c017ac4052e02460bf7b6a023b08d1c8',
'domain':' common',
}
data = urllib.parse.urlencode(data).encode('utf-8')
request = urllib.request.Request(url=url, data=data, headers=headers)
response = urllib.request.urlopen(request)
content =  response.read().decode('utf-8')
print(type(content))
import json
obj = json.loads(content)
print(obj)